package awesome.cpu.structure;

import awesome.cpu.utils.Mode;

public class MemoryRegister extends SequentialComponent {
	
	private static boolean outputDebug = false;
	
	public final static int KEY_MEM_DATA = 1;
	int mMemData;
	
	public final static int KEY_MEM_REG = 2;
	int mMemReg;
	
	private final static MemoryRegister mInstance = new MemoryRegister();
	
	private MemoryRegister() {}
	
	public static MemoryRegister getInstance() {
		return mInstance;
	}

	@Override
	void onClockTick() {
		mMemReg = mMemData;
		if (outputDebug && Mode.getDebugLevel() >= Mode.DEBUG_LEVEL_PRINT_ALL)
			System.out.println("MR = " + mMemReg);
	}

	@Override
	boolean setData(int keyInterface, int data) {
		switch (keyInterface) {
		case KEY_MEM_DATA:
			mMemData = data;
			return true;
		}
		return false;
	}

	@Override
	int getData(int keyInterface) {
		switch (keyInterface) {
		case KEY_MEM_REG:
			return mMemReg;
		}
		return 0;
	}

}
